package com.fire.threadpool.interceptLongTimeThread;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;

/**
 * @date 2022/3/24
 * @author zwd
 * @email zwd@hhh.com
 */
public class DelayTaskTest {
	public static void main(String[] args) {
		DelayTask delayThread1 = new DelayTask("DelayThread1",1000);
		DelayTask delayThread2 = new DelayTask("DelayThread2", 100);
		DelayTask delayThread3 = new DelayTask("DelayThread3", 10);
		DelayQueue<DelayTask> delayTasks = new DelayQueue<>();
		delayTasks.add(delayThread1);
		delayTasks.add(delayThread2);
		delayTasks.add(delayThread3);
		//删除某个元素
		delayTasks.remove(delayThread1);
		while (true) {
			Delayed take = null;
			try {
				take = delayTasks.take();
			}
			catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(take);
		}


	}

	static class DelayThread implements Runnable{

		@Override
		public void run() {
			System.out.println("DelayThread is called");
		}
	}
}
